package com.lyc.lojbackendjudgeservice.judge;


import com.lyc.lojbackendjudgeservice.judge.strategy.*;
import com.lyc.lojbackendjudgeservice.judge.strategy.impl.*;
import com.lyc.lojbackendmodel.model.codesandbox.JudgeInfo;
import com.lyc.lojbackendmodel.model.entity.QuestionSubmit;
import org.springframework.stereotype.Service;

/**
 * 判题管理，简化调用
 */
@Service
public class JudgeManager {
    /**
     * 执行判题
     *
     * @param judgeContext
     * @return
     */
    JudgeInfo doJudge(JudgeContext judgeContext) {
        QuestionSubmit questionSubmit = judgeContext.getQuestionSubmit();
        JudgeStrategy judgeStrategy;
        String language = questionSubmit.getLanguage();
        switch (language) {
            case "java":
                judgeStrategy = new JavaLanguageJudgeStrategy();
                break;
            case "cpp":
                judgeStrategy = new CppLanguageJudgeStrategy();
                break;
            case "python":
                judgeStrategy = new PythonLanguageJudgeStrategy();
                break;
            case "c":
                judgeStrategy = new CLanguageJudgeStrategy();
                break;
            case "go":
                judgeStrategy = new GoLangLanguageJudgeStrategy();
                break;
            default:
                judgeStrategy = new DefaultJudgeStrategy();
        }
        return judgeStrategy.doJudge(judgeContext);
    }
}
